#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
typedef struct
{
    int hours;
    int minutes;
    int seconds;
} Time;

void countdown(Time *time)
{
    time->hours = 1, time->minutes =0 , time->seconds = 0;
    int pass_time = 0;
    while (time->hours > 0 || time->minutes > 0 || time->seconds > 0)
    {

        print_time(time);
        sleep(1); // 暂停一秒

        // 减少一秒
        if (time->seconds > 0)
        {
            time->seconds--;
            pass_time++;
        }
        else if (time->minutes > 0)
        {
            time->minutes--;
            time->seconds = 59;
        }
        else if (time->hours > 0)
        {
            time->hours--;
            time->minutes = 59;
            time->seconds = 59;
        }

        if (pass_time % 900 == 0 && pass_time != 0)
        {
            printf("\r15 min pass!    \n");
        }
    }
    printf("\n倒计时结束!\n");
}

void print_time(Time *time)
{
    // 使用 \r 来覆盖之前的输出
    printf("\r倒计时: %02d:%02d:%02d", time->hours, time->minutes, time->seconds);
    fflush(stdout); // 确保输出立即显示在屏幕上
}
int main()
{
    Time start_time;
    countdown(&start_time);
}